package com.yaoxuguang.concurrence.threadBase.yield;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.threadBase.yield
 * @Description: yield方法
 * @date 2018年12月17日15:57
 */
public class MyThread extends  Thread{
    @Override
    public void run() {
        long startTime = System.currentTimeMillis();
        int count = 0;
        for (int i = 0; i <500000; i++) {
            count = count + i;
            //该线程放弃cpu，让其他任务执行
            Thread.yield();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("总耗时："+(endTime-startTime)+"ms");
    }
}
